﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using Sunny.UI;

namespace IOCtrls
{
    public partial class InputCtr : UserControl
    {
        private string _text;
        private bool _state;

        public InputCtr()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);

            SetStyle(
                ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.ResizeRedraw
                | ControlStyles.Selectable
                | ControlStyles.AllPaintingInWmPaint
                | ControlStyles.UserPaint
                | ControlStyles.SupportsTransparentBackColor,
                true);

        }

        protected override void OnSizeChanged(EventArgs e)
        {
            ResizeLight();
            base.OnSizeChanged(e);
        }

        private void ResizeLight()
        {
            uiLight1.Height = uiLight1.Width = Height - 4;
        }

        protected override void OnResize(EventArgs e)
        {
            ResizeLight();
            base.OnResize(e);
        }

        [Browsable(true), Category("自定义属性")]
        public override string Text
        {
            get => _text;
            set
            {
                _text = value;
                uiLabel1.Text = _text;
            }
        }

        [Description("True 为On False 为Off"), Category("自定义属性")]
        public bool State
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
                uiLight1.State = value ? UILightState.On : UILightState.Off;
            }
        }

        public Action<object> LabelDoubleClick;

        private void uiLabel1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            LabelDoubleClick?.Invoke(this);
        }
    }
}   